/*
 * @lc app=leetcode.cn id=844 lang=javascript
 *
 * [844] 比较含退格的字符串
 */

// @lc code=start

let myStack = [];
function sizeS() {
    return myStack.length;
}
function emptyS() {
    return sizeS() === 0;
}
function pushS(ele) {
    myStack.push(ele);
}
function popS() {
    return myStack.pop();
}
function peekS() {
    if (emptyS()) {
        return undefined;
    }
    return myStack[sizeS() - 1];
}
function clearS() {
    myStack = [];
}

function dealString(str) {
    str.split('').forEach(element => {
        if (element === '#') {
            popS();
        } else {
            pushS(element);
        }
    });
    const res = myStack.join();
    clearS();
    return res;
}

/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
var backspaceCompare = function(s, t) {
    return dealString(s) === dealString(t)
};
// @lc code=end

